package com.mhxy.service.impl;

import com.mhxy.constant.PicConstants;
import com.mhxy.entity.FindPicResult;
import com.mhxy.service.AbstractTask;
import com.mhxy.util.DateUtil;
import com.mhxy.util.FuzzyPicUtil;
import com.mhxy.util.ThreadUtil;
import com.mhxy.util.TimeUtil;
import com.sun.jna.platform.win32.WinDef;
import lombok.extern.slf4j.Slf4j;

/**
 * 召唤灵乐园
 */
@Slf4j
public class PetPartTaskImpl extends AbstractTask {

    public PetPartTaskImpl(WinDef.HWND hwnd_0) {
        super(hwnd_0);
    }

    @Override
    public Boolean before() throws Exception {
        if (DateUtil.getNowDay() != 3) {
            log.error("【{}】今天不是周3，任务结束！", getTaskName());
            return false;
        }
        // 判断时间是否为21:00~21:40
        if (!TimeUtil.isAfter(21, 0)) {
            log.info("【{}】未在活动时间！", getTaskName());
            return false;
        }
        return true;
    }

    @Override
    public Boolean execute() throws Exception {
        // 判断时间是否为21:00~21:40
        while (!TimeUtil.isAfter(21, 40)) {
            if (FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.普通副本_战斗时钟, 1)) {
                ThreadUtil.sleep3();
                FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.普通副本_进入战斗);
            }
            ThreadUtil.sleep(2000);
            findBattle(3000);
        }

        return true;
    }

    @Override
    public Boolean after() throws Exception {
        return true;
    }

    @Override
    public String getTaskName() throws Exception {
        return "召唤灵乐园";
    }
}
